#pragma once

#include "assert.h"
#include "decision.h"
#include "problem.h"

namespace solver 
{

	class cell 
	{
	public:
		int row_idx;
		pchoices dec;
		bool star;
		literal lit;
	};

	class table_builder
	{
	private:
		std::list<cell> cells;
		int current_row_idx;

	public:

		table_builder()
		{
			clear();
		}

		void new_row()
		{
			current_row_idx++;
		}

		void clear()
		{
			current_row_idx = 0;
			cells.clear();
		}

		bool add(problem& cur_problem, int variable_ref, pdecision d1, pdecision d2)
		{
			// first add d2 != variable_ref
			auto vlit1 = d1->get_lit(variable_ref);
			auto vlit2 = d2->get_lit(variable_ref);

			// make sure that these refs are really found
			assert(vlit1.ref == variable_ref);
			assert(vlit2.ref == variable_ref);

			for (int i = 0; i < d2->num_literals; i++) 
			{
				auto tlit = d2->literals[i];
				if (tlit == vlit2)
					continue;
				cell c1,c2;
				c1.lit = vlit1;
				c1.row_idx = current_row_idx;
				c1.dec = d1;
				c1.star = false;
				add(cur_problem, c1);
				c2.lit = vlit2;
				c2.row_idx = current_row_idx;
				c2.dec = d1;
				c2.star = false;
				add(cur_problem, c1);
			}

			return true;
		}

		void add(problem& cur_problem, cell& cell1)
		{
			cell new_cell = cell1;
			new_cell.row_idx = current_row_idx;
		}

		void add_star(problem& cur_problem, cell& cell1)
		{
			cell new_cell = cell1;
			new_cell.row_idx = current_row_idx;
		}

	};

	class table
	{
		cell *cells;
		int num_rows;
		int num_cols;

	public:
		
		void add_row(cell& cell1, cell& cell2)
		{

		}
	};

}